package text;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by IntelliJ IDEA.
 * User: vladimir
 * Date: 01.08.11
 * Time: 19:14
 * To change this template use File | Settings | File Templates.
 */
public class Test {
    public static void main(String[] args) {
        String text = "[first|last] blabla 15454 #{common.props} ${something.else} and wuala [val.one|val.two] blabls [elseval1|elseval2]";
//        String text = "I lost my wallet. Once again I lost my passport and I lost my: money";
//        String text = "I lost my wallet..";
//        text = text.replaceAll("\\[.*\\|\\]", "Ooops");
//        System.out.println(text);

        Pattern pattern = Pattern.compile("\\[[^\\]]*\\]");
        Matcher matcher = pattern.matcher(text);

        while (matcher.find()) {
            System.out.println(matcher.start());
            System.out.println(matcher.end());
            System.out.println(text.substring(matcher.start() + 1, matcher.end() - 1).split("\\|")[0]);
        }
//        Random random = new Random();
//        for (int i = 0; i < 100; i++) {
//            System.out.println(1000 + (int) (Math.random() * 1000));
//        }
    }
}
